package com.ruoyi.kis.util;

import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.ruoyi.kis.Vars.Constants;
import com.ruoyi.kis.controller.KisApiController;
import com.ruoyi.kis.domain.DispatchOrderF;
import com.ruoyi.kis.service.IKisService;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhanglm
 * @CreateDate: 2025-03-02 14:57
 * @FullNameClass: com.ruoyi.kis.util.HttpSendWmsUtil
 * @Description:
 */
@Component
public class HttpSendWmsUtil {


    private static Boolean open;
    private static String username;
    private static String password;
    private static String Authorization;


    @Value("${kis.open}")
    public void  setOpen(Boolean open) {
        HttpSendWmsUtil.open = open;
    }
    @Value("${kis.username}")
    public void setUsername(String username) {
        HttpSendWmsUtil.username = username;
    }
    @Value("${kis.password}")
    public void setPassword(String password) {
        HttpSendWmsUtil.password = password;
    }
    @Value("${kis.Authorization}")
    public void setAuthorization(String authorization) {
        HttpSendWmsUtil.Authorization = authorization;
    }
    private static final Logger LOGGER = LoggerFactory.getLogger(HttpSendWmsUtil.class);
    public static String sendWms(String url, String jsonString) {
        String post = "";
        if(open){
            String basicAuth = HttpUtil.buildBasicAuth(username, password, Charset.defaultCharset());
            post = HttpRequest.post(url)
                    .header("Content-Type", "application/json")
                    .header("Authorization", basicAuth)
                    .body(jsonString)
                    .execute().body();
            return post;
        }else{
            post = HttpUtil.post(url, jsonString);

        }
        return post;
    }

}
